using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Collections;

namespace ActorSystem
{
	/// <summary>
	/// Do the communication in the system
	/// Tell the other nodes, that this node is alive and kicking
	/// FUTURE: Tell the workload of this node. Used to loadbalancing
	/// </summary>
	class ControlServer
	{
		private Control localControl;
		
		//This field need to be synchronized
		public ArrayList NonLocalActors { get; set; }
		
		public ControlServer(Control c)
		{
			this.localControl = c;
			//Start a thread with the function UpdateNonLocalActorList
		}
		
		public void UpdateNonLocalActorList()
		{
			
		}
		
		public void BroadCastListOfActors()
		{
			
		}
		
		public void RecieveMessages()
		{
			//Recieve a message, and send it to control
		}
		
		public void SendMessage(Message msg) 
		{
			//If msg is to local, send it back, else send it to recipient
			if (msg.To.Host.Equals(localControl.GetHostIp().ToString()))
			{
				localControl.RecieveMessage(msg);
			}
		}
	}
}
